package com.gosophia.logContent.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.OrderCondition;
import com.gosophia.commons.Page;
import com.gosophia.commons.PropertyFilter;
import com.gosophia.commons.web.action.BaseAjaxAction;
import com.gosophia.logManagement.dto.LogContentDTO;
import com.gosophia.logManagement.ws.LogManagementWebService;

@Scope("prototype")
@Controller("GetPageLogContentAction")
public class GetPageLogContentAction  extends BaseAjaxAction<LogContentDTO> {

	private static final long serialVersionUID = 1832414466064233509L;
    @Autowired
	private LogManagementWebService logManagementWebService;
    
    private Boolean searchFlg = false;
	
	private Integer pageNo;

    private Integer pageSize;

	@Override
	public LogContentDTO getDetailData() {
		return this.detailData;
	}

	@Override
	public Page<LogContentDTO> getPage() {
		return this.page;
	}

	@Override
	public void setOrderConditions(List<OrderCondition> orderConditions) {
		this.orderConditions = orderConditions;
		
	}

	@Override
	public void setPropertyFilters(List<PropertyFilter> propertyFilters) {
		this.propertyFilters = propertyFilters;	
	}

	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Boolean getSearchFlg() {
		return searchFlg;
	}

	public void setSearchFlg(Boolean searchFlg) {
		this.searchFlg = searchFlg;
	}

	@Override
	public String _execute() throws Exception {
	    if(pageNo==null) {
	    	pageNo = 1;
	    }
	    if(searchFlg.booleanValue() == false) {
	    	this.page = logManagementWebService.findSampleLogContentsByPage(pageNo, this.searchString, pageSize, orderConditions);
	    }else {
	    	if(propertyFilters.size()!=0&&propertyFilters!=null) {
		    	   for(PropertyFilter p1:propertyFilters) {
		    		   if("eventTime".equals(p1.getPropertyName())){
		    		       p1.setToCharFormat("yyyy-MM-dd hh24:mi:ss");
		    		   }
		    	   }
		    	}
	    	this.page = logManagementWebService.findLogContentsByPage(pageNo, pageSize, propertyFilters, orderConditions);
	    }
	  
	    if(this.page.getTotalCount()<=0) {
	    	super.getRequestResult().setRsltCode("1");
	    }else {
	    	super.getRequestResult().setRsltCode("0");
	    }
        return SUCCESS;
	}

}
